import Config from "./Config.js";
import Direction from "./Direction.js";
import Tool from "./Tool.js";
import Tank from "./Tank.js";

export default class Enemy extends Tank {
    constructor(x = 0, y = 0, width = Config.BlockSize, height = Config.BlockSize, imgSrc = Config.ImageAssets.EnemyImgs.bottom) {
        super(x, y, width, height, imgSrc);
        this.life = 8;
        this.speed = 100;
        this.life = 10;
        this.attack = 5;
        this.direction = Direction.BOTTOM;
        this.attackSpeed = 1500;
        this.attackCoolDonw = 0;
        this.turnTimer = 1500;
    }

    autoRun(collisionArr) {
        // 随机方向
        this.turnTimer -= Config.GameUpdateTick;
        if (this.turnTimer <= 0) {
            this.turnTimer = 1500;
            let ran = Tool.random(1, 100);
            if (ran <= 10) {
                this.direction = Direction.TOP;
                this.img.src = Config.ImageAssets.EnemyImgs.top;
            } else if (ran <= 40) {
                this.direction = Direction.RIGHT;
                this.img.src = Config.ImageAssets.EnemyImgs.right;
            } else if (ran <= 70) {
                this.direction = Direction.BOTTOM;
                this.img.src = Config.ImageAssets.EnemyImgs.bottom;
            } else {
                this.direction = Direction.LEFT;
                this.img.src = Config.ImageAssets.EnemyImgs.left;
            }
        }

        this.move(collisionArr);
    }
}